<template>
	<view>
		<u-navbar :is-back="true" title="接诊语" title-color="white" :background="{backgroundColor: '#00a8ff'}"
			:border-bottom="false">
			<!-- <view class="navbar-right" slot="right" style="padding-right: 20rpx;color: #FFFFFF;" @click="manage()">
				管理
			</view> -->
		</u-navbar>
		<view class="u-p-15 u-font-12" style="background-color: #f3f4f5;color: #b2b2b2;">
			已建常用语（{{list.length}}/100）
		</view>
		<view class="" style="padding: 0rpx 26rpx;">
			<u-cell-group>
				<u-swipe-action :show="item.show" :index="index" v-for="(item, index) in list" :key="item.id"
					@click="click" @open="open" :options="options">
					<u-cell-item :title="item.content" :arrow="false">
					</u-cell-item>
				</u-swipe-action>
			</u-cell-group>
			<buttonContent @aClick="add" txt="+ 添加常用语"></buttonContent>
		</view>
	</view>
</template>

<script>
	import buttonContent from '@/components/custom/buttonContent.vue'
	export default {
		components: {
			buttonContent
		},
		data() {
			return {
				options: [{
					text: '删除',
					style: {
						backgroundColor: '#dd524d'
					}
				}],
				id: '',
				list: '',
			}
		},
		onLoad(e) {
			console.log(e);
			this.id = e.id;
		},
		onShow() {
			this.getIndexList(this.id)
		},
		methods: {
			// 获取消息列表
			getIndexList(id) {
				this.$apiCase.quIcontent({
					cate_id: id
				}).then((res) => {
					console.log("res.data.data: ", res.data.data);
					this.list = res.data.data;
				}).catch((err) => {
					console.log('request fail', err);
				})
			},

			openinfo(url) {
				uni.navigateTo({
					url: url,
				});
			},
			click(index, index1) {
				console.log(this.list[index].id);
				if (index1 == 0) {

					this.del(this.list[index].id)
					this.list.splice(index, 1);
				}else{
					
				}
			},
			del(id){
				this.$apiCase.quIcontentdel({
					id:id
				}).then((res) => {
					console.log("res.data: ", res.data.code);
					if(res.data.code==1){
						uni.showToast({
							title:'删除成功'
						})
					}
				}).catch((err) => {
					console.log('request fail', err);
				})
			},
			// 如果打开一个的时候，不需要关闭其他，则无需实现本方法
			open(index) {
				// 先将正在被操作的swipeAction标记为打开状态，否则由于props的特性限制，
				// 原本为'false'，再次设置为'false'会无效

				this.list[index].show = true;
				this.list.map((val, idx) => {
					if (index != idx) this.list[idx].show = false;
				})
			},
			add(res) {
				console.log(res);
				console.log("点击了添加常用语");
				this.openinfo('/pages/tabBar/my/fastReply/fastReplyList/addExp?id=' + this.id)
			},
			manage() {
				console.log("管理")
			}
		}
	}
</script>

<style lang="scss" scoped>

</style>
